import AppNode from "../app_node";
import { RegClass } from "../serialize";
import { H5Utils } from "../utils";
import PrefabStr from "./folder.prefab.html?raw"

@RegClass("Folder")
export default class Folder extends AppNode {
    isFold = false;

    lbArrow: HTMLSpanElement = null;
    lbTitle: HTMLSpanElement = null;

    refCtor(refEle: Element): void {
        this.lbTitle.innerText = refEle.getAttribute("legend") || "标题";

        let children = Array.from(refEle.children);
        for (let i = 0; i < children.length; i++) {
            let ele = children[i];
            ele.remove();
            this.ele.appendChild(ele);
        }
    }
    onToggle() {
        this.isFold = !this.isFold;

        if (this.isFold) {
            this.ele.setAttribute("folded", "");
            this.lbArrow.innerText = "+";
        }
        else {
            this.ele.removeAttribute("folded");
            this.lbArrow.innerText = "-";
        }
    }
    static get __BindPrefab__(): string {
        return PrefabStr;
    }
};